package c.j.a.d.a;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Environment;
import android.text.TextUtils;
import c.j.a.c.m.d;
import c.j.a.c.y.a.j;
import c.j.a.d.a.h.e;
import c.j.a.d.a.h.f;
import c.j.a.d.b.d.b0;
import c.j.a.d.b.d.h;
import c.j.a.d.b.e.o;
import c.j.a.d.b.e.p;
import c.j.a.d.b.j.q;
import com.huawei.hms.adapter.internal.BaseCode;
import com.pgl.sys.ces.out.ISdkLite;
import com.ss.android.socialbase.appdownloader.DownloadReceiver;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: AppDownloader */
public class i {
    public static final String j = "i";
    public static volatile i k = null;
    public static boolean l = false;
    public static boolean m = false;
    public c.j.a.d.a.h.b a;
    public d b;
    public h.d c;
    public c.j.a.c.m.c d;
    public String e;
    public DownloadReceiver f;
    public String g;
    public j h;
    public h i;

    /* compiled from: AppDownloader */
    public class a implements b0 {
        public void a(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i) {
            h.d dVar = i.this.c;
            if (dVar != null) {
                dVar.a(cVar, aVar, i);
            }
        }
    }

    /* compiled from: DefaultDownloadLaunchHandler */
    public class c implements o {
        public List<Integer> a;
        public BroadcastReceiver b;

        /* compiled from: DefaultDownloadLaunchHandler */
        public class a implements Runnable {
            public final /* synthetic */ List a;
            public final /* synthetic */ int b;

            public a(List list, int i) {
                this.a = list;
                this.b = i;
            }

            public void run() {
                try {
                    c.this.d(this.a, this.b);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        /* compiled from: DefaultDownloadLaunchHandler */
        public class b extends BroadcastReceiver {

            /* compiled from: DefaultDownloadLaunchHandler */
            public class a implements Runnable {
                public final /* synthetic */ Context a;

                public a(Context context) {
                    this.a = context;
                }

                public void run() {
                    try {
                        List list = c.this.a;
                        if (list != null) {
                            if (!list.isEmpty()) {
                                int size = c.this.a.size();
                                Integer[] numArr = new Integer[size];
                                c.this.a.toArray(numArr);
                                c.this.a.clear();
                                for (int i = 0; i < size; i++) {
                                    com.ss.android.socialbase.downloader.g.c k = c.j.a.d.b.e.i.a(this.a).k(numArr[i].intValue());
                                    if (k != null) {
                                        if (k.p0() != -5) {
                                            if (k.p0() == -2) {
                                                if (!k.h()) {
                                                }
                                            }
                                        }
                                        c.this.a(this.a, k, true, 2);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

            public void onReceive(Context context, Intent intent) {
                context = context.getApplicationContext();
                if (c.j.a.d.b.n.a.t(context)) {
                    c.j.a.d.b.g.a.d("LaunchResume", "onReceive : wifi connected !!!");
                    c.j.a.d.b.e.b.q().execute(new a(context));
                    try {
                        context.unregisterReceiver(c.this.b);
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                    c.this.b = null;
                }
            }
        }

        /* JADX WARNING: Removed duplicated region for block: B:60:0x015a  */
        /* JADX WARNING: Removed duplicated region for block: B:24:0x0095  */
        /* JADX WARNING: Removed duplicated region for block: B:60:0x015a  */
        /* JADX WARNING: Removed duplicated region for block: B:81:0x01fe  */
        public final void a(android.content.Context r20, com.ss.android.socialbase.downloader.g.c r21, boolean r22, int r23) {
            /*
            r19 = this;
            r1 = r19;
            r2 = r21;
            if (r2 == 0) goto L_0x02c1;
        L_0x0006:
            r0 = r2.t;
            if (r0 != 0) goto L_0x000c;
        L_0x000a:
            goto L_0x02c1;
        L_0x000c:
            r0 = r21.p0();
            r3 = -5;
            r4 = ", canShowNotification = ";
            r5 = "LaunchResume";
            r6 = "dbjson_last_start_download_time";
            r7 = 4622945017495814144; // 0x4028000000000000 float:0.0 double:12.0;
            r9 = 4634766966517661696; // 0x4052000000000000 float:0.0 double:72.0;
            r11 = 0;
            if (r0 != r3) goto L_0x015f;
        L_0x001e:
            r3 = r2.u;
            r12 = "application/ttpatch";
            r3 = r12.equalsIgnoreCase(r3);
            if (r3 != 0) goto L_0x002e;
        L_0x0028:
            r3 = r21.F();
            if (r3 != 0) goto L_0x015f;
        L_0x002e:
            r0 = r21.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r3 = "failed_resume_max_count";
            r3 = r0.b(r3, r11);
            r11 = "failed_resume_max_hours";
            r9 = r0.a(r11, r9);
            r11 = "failed_resume_min_hours";
            r7 = r0.a(r11, r7);
            r11 = java.lang.System.currentTimeMillis();
            r13 = r21.V();
            r14 = "last_failed_resume_time";
            if (r13 >= r3) goto L_0x0086;
        L_0x0054:
            r21.M();
            r3 = r2.D0;
            r23 = r4;
            r13 = r5;
            r4 = 0;
            r3 = r3.optLong(r6, r4);
            r3 = r11 - r3;
            r3 = (double) r3;
            r5 = 4704985352480227328; // 0x414b774000000000 float:0.0 double:3600000.0;
            r9 = r9 * r5;
            r15 = (r3 > r9 ? 1 : (r3 == r9 ? 0 : -1));
            if (r15 >= 0) goto L_0x0089;
        L_0x0070:
            r21.N();
            r3 = r2.C0;
            r9 = 0;
            r3 = r3.optLong(r14, r9);
            r3 = r11 - r3;
            r3 = (double) r3;
            r7 = r7 * r5;
            r5 = (r3 > r7 ? 1 : (r3 == r7 ? 0 : -1));
            if (r5 <= 0) goto L_0x0089;
        L_0x0084:
            r3 = 1;
            goto L_0x008a;
        L_0x0086:
            r23 = r4;
            r13 = r5;
        L_0x0089:
            r3 = 0;
        L_0x008a:
            r4 = r21.h();
            if (r4 == 0) goto L_0x0093;
        L_0x0090:
            if (r22 == 0) goto L_0x0093;
        L_0x0092:
            r3 = 1;
        L_0x0093:
            if (r3 == 0) goto L_0x012c;
        L_0x0095:
            r4 = "failed_resume_need_wifi";
            r5 = 1;
            r4 = r0.b(r4, r5);
            if (r4 != r5) goto L_0x00a0;
        L_0x009e:
            r4 = 1;
            goto L_0x00a1;
        L_0x00a0:
            r4 = 0;
        L_0x00a1:
            r6 = "failed_resume_need_wait_wifi";
            r7 = 0;
            r0 = r0.b(r6, r7);
            if (r0 != r5) goto L_0x00ac;
        L_0x00aa:
            r0 = 1;
            goto L_0x00ad;
        L_0x00ac:
            r0 = 0;
        L_0x00ad:
            if (r22 != 0) goto L_0x00e3;
        L_0x00af:
            if (r4 == 0) goto L_0x00e3;
        L_0x00b1:
            if (r0 != 0) goto L_0x00b4;
        L_0x00b3:
            goto L_0x00e3;
        L_0x00b4:
            r0 = r1.a;
            if (r0 != 0) goto L_0x00bf;
        L_0x00b8:
            r0 = new java.util.ArrayList;
            r0.<init>();
            r1.a = r0;
        L_0x00bf:
            r0 = r21.g0();
            r4 = r1.a;
            r5 = java.lang.Integer.valueOf(r0);
            r4 = r4.contains(r5);
            if (r4 != 0) goto L_0x00d8;
        L_0x00cf:
            r4 = r1.a;
            r0 = java.lang.Integer.valueOf(r0);
            r4.add(r0);
        L_0x00d8:
            r0 = 1;
            r2.g = r0;
            r0 = c.j.a.d.b.j.a0.a();
            r0.c(r2);
            goto L_0x012c;
        L_0x00e3:
            r1.b(r2, r3, r4);
            r21.N();
            r0 = r2.C0;	 Catch:{ Exception -> 0x00ef }
            r0.put(r14, r11);	 Catch:{ Exception -> 0x00ef }
            goto L_0x00f3;
        L_0x00ef:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x00f3:
            r0 = r21.V();
            r0 = r0 + 1;
            r21.N();
            r4 = r2.C0;	 Catch:{ Exception -> 0x0104 }
            r5 = "failed_resume_count";
            r4.put(r5, r0);	 Catch:{ Exception -> 0x0104 }
            goto L_0x0108;
        L_0x0104:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x0108:
            r21.U();
            r0 = r21.h();
            if (r0 == 0) goto L_0x012a;
        L_0x0111:
            if (r22 == 0) goto L_0x012a;
        L_0x0113:
            r0 = 1;
            r2.G0 = r0;
            r0 = c.j.a.d.a.i.j();
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.d.b.e.b.a();
            r0 = c.j.a.d.b.e.i.a(r0);
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.d.b.e.b.a;
        L_0x012a:
            r0 = 1;
            goto L_0x012d;
        L_0x012c:
            r0 = 0;
        L_0x012d:
            r4 = "launchResume, name = ";
            r4 = c.b.a.a.a.g(r4);
            r5 = r21.j0();
            r4.append(r5);
            r5 = r23;
            r4.append(r5);
            r4.append(r3);
            r3 = ", downloadResumed = ";
            r4.append(r3);
            r4.append(r0);
            r3 = r4.toString();
            r4 = r13;
            c.j.a.d.b.g.a.e(r4, r3);
            r3 = c.j.a.d.a.i.j();
            r3 = r3.d;
            if (r3 == 0) goto L_0x02c1;
        L_0x015a:
            r3.a(r2, r0);
            goto L_0x02c1;
        L_0x015f:
            r18 = r5;
            r5 = r4;
            r4 = r18;
            r3 = -3;
            if (r0 != r3) goto L_0x0262;
        L_0x0167:
            r3 = r21.g0();
            r3 = c.j.a.d.b.l.a.d(r3);
            r11 = "uninstall_can_not_resume_for_force_task";
            r12 = 0;
            r3 = r3.k(r11, r12);
            if (r3 == 0) goto L_0x017f;
        L_0x0178:
            r3 = r2.y;
            r3 = c.j.a.d.b.n.a.v(r2, r12, r3);
            goto L_0x0183;
        L_0x017f:
            r3 = r21.F();
        L_0x0183:
            if (r3 == 0) goto L_0x0262;
        L_0x0185:
            r0 = r21.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r3 = c.j.a.d.a.h.i(r20, r21);
            if (r3 == 0) goto L_0x0194;
        L_0x0193:
            return;
        L_0x0194:
            r3 = "uninstall_resume_max_count";
            r3 = r0.b(r3, r12);
            r11 = "uninstall_resume_max_hours";
            r9 = r0.a(r11, r9);
            r11 = "uninstall_resume_min_hours";
            r7 = r0.a(r11, r7);
            r11 = java.lang.System.currentTimeMillis();
            r0 = r21.W();
            r13 = "last_unins_resume_time";
            if (r0 >= r3) goto L_0x01e1;
        L_0x01b2:
            r21.M();
            r0 = r2.D0;
            r14 = 0;
            r14 = r0.optLong(r6, r14);
            r14 = r11 - r14;
            r14 = (double) r14;
            r16 = 4704985352480227328; // 0x414b774000000000 float:0.0 double:3600000.0;
            r9 = r9 * r16;
            r0 = (r14 > r9 ? 1 : (r14 == r9 ? 0 : -1));
            if (r0 >= 0) goto L_0x01e1;
        L_0x01cb:
            r21.N();
            r0 = r2.C0;
            r9 = 0;
            r9 = r0.optLong(r13, r9);
            r9 = r11 - r9;
            r9 = (double) r9;
            r7 = r7 * r16;
            r0 = (r9 > r7 ? 1 : (r9 == r7 ? 0 : -1));
            if (r0 <= 0) goto L_0x01e1;
        L_0x01df:
            r0 = 1;
            goto L_0x01e2;
        L_0x01e1:
            r0 = 0;
        L_0x01e2:
            r3 = "uninstallResume, name = ";
            r3 = c.b.a.a.a.g(r3);
            r6 = r21.j0();
            r3.append(r6);
            r3.append(r5);
            r3.append(r0);
            r3 = r3.toString();
            c.j.a.d.b.g.a.e(r4, r3);
            if (r0 == 0) goto L_0x02c1;
        L_0x01fe:
            r0 = c.j.a.d.b.o.d.a();
            r3 = r21.g0();
            r0 = r0.d(r3);
            if (r0 != 0) goto L_0x022a;
        L_0x020c:
            r0 = new c.j.a.d.a.j.a;
            r5 = r21.g0();
            r6 = r21.j0();
            r7 = r2.e;
            r8 = r2.b;
            r9 = r2.h;
            r3 = r0;
            r4 = r20;
            r3.m6389init(r4, r5, r6, r7, r8, r9);
            r3 = c.j.a.d.b.o.d.a();
            r3.c(r0);
            goto L_0x022d;
        L_0x022a:
            r0.d(r2);
        L_0x022d:
            r3 = r2.T;
            r0.c = r3;
            r0.b = r3;
            r3 = r21.o0();
            r4 = 0;
            r5 = 0;
            r0.a(r3, r4, r5, r5);
            r21.N();
            r0 = r2.C0;	 Catch:{ Exception -> 0x0245 }
            r0.put(r13, r11);	 Catch:{ Exception -> 0x0245 }
            goto L_0x0249;
        L_0x0245:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x0249:
            r0 = r21.W();
            r0 = r0 + 1;
            r21.N();
            r3 = r2.C0;	 Catch:{ Exception -> 0x025a }
            r4 = "unins_resume_count";
            r3.put(r4, r0);	 Catch:{ Exception -> 0x025a }
            goto L_0x025e;
        L_0x025a:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x025e:
            r21.U();
            goto L_0x02c1;
        L_0x0262:
            r3 = -2;
            if (r0 != r3) goto L_0x02c1;
        L_0x0265:
            r0 = r21.h();
            if (r0 == 0) goto L_0x02c1;
        L_0x026b:
            if (r22 == 0) goto L_0x0296;
        L_0x026d:
            r0 = 1;
            r1.b(r2, r0, r0);
            r21.U();
            r2.G0 = r0;
            r3 = c.j.a.d.a.i.j();
            r3 = r3.d;
            if (r3 == 0) goto L_0x0281;
        L_0x027e:
            r3.a(r2, r0);
        L_0x0281:
            r0 = c.j.a.d.a.i.j();
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.d.b.e.b.a();
            r0 = c.j.a.d.b.e.i.a(r0);
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.d.b.e.b.a;
            goto L_0x02c1;
        L_0x0296:
            r0 = r1.a;
            if (r0 != 0) goto L_0x02a1;
        L_0x029a:
            r0 = new java.util.ArrayList;
            r0.<init>();
            r1.a = r0;
        L_0x02a1:
            r0 = r21.g0();
            r3 = r1.a;
            r4 = java.lang.Integer.valueOf(r0);
            r3 = r3.contains(r4);
            if (r3 != 0) goto L_0x02ba;
        L_0x02b1:
            r3 = r1.a;
            r0 = java.lang.Integer.valueOf(r0);
            r3.add(r0);
        L_0x02ba:
            r0 = c.j.a.d.b.j.a0.a();
            r0.c(r2);
        L_0x02c1:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.i$c.a(android.content.Context, com.ss.android.socialbase.downloader.g.c, boolean, int):void");
        }

        public final void b(com.ss.android.socialbase.downloader.g.c cVar, boolean z, boolean z2) {
            JSONObject jSONObject;
            l lVar = new l(c.j.a.d.b.e.b.a(), cVar.d);
            lVar.d = cVar.j0();
            lVar.e = cVar.b;
            lVar.f = cVar.e;
            lVar.h = cVar.t;
            z2 = cVar.g || z2;
            lVar.j = z2;
            lVar.l = cVar.h;
            lVar.m = cVar.u;
            lVar.g = cVar.i;
            lVar.q = true;
            lVar.w = cVar.m;
            lVar.x = cVar.n;
            lVar.c = cVar.s;
            int i = cVar.r;
            if (i < 1000) {
                i = 1000;
            }
            lVar.F = i;
            lVar.G = cVar.q;
            lVar.r = z;
            lVar.n = cVar.v;
            lVar.s = cVar.w;
            lVar.t = cVar.y;
            lVar.u = cVar.c();
            lVar.A = cVar.C;
            lVar.B = cVar.H;
            lVar.D = cVar.K;
            lVar.E = cVar.l0;
            lVar.v = cVar.o;
            lVar.H = cVar.J;
            lVar.y = cVar.A;
            lVar.z = cVar.B;
            String g = cVar.g();
            if (!TextUtils.isEmpty(g)) {
                try {
                    jSONObject = new JSONObject(g);
                } catch (Throwable unused) {
                }
                lVar.L = jSONObject;
                lVar.M = cVar.M;
                lVar.O = cVar.Z();
                i.j().a(lVar);
            }
            jSONObject = null;
            lVar.L = jSONObject;
            lVar.M = cVar.M;
            lVar.O = cVar.Z();
            i.j().a(lVar);
        }

        public void c(List<com.ss.android.socialbase.downloader.g.c> list, int i) {
            if (c.j.a.d.b.n.a.Q()) {
                c.j.a.d.b.e.b.q().execute(new a(list, i));
            } else {
                d(list, i);
            }
        }

        public final void d(List<com.ss.android.socialbase.downloader.g.c> list, int i) {
            if (!(list == null || list.isEmpty())) {
                c.j.a.c.m.c cVar = i.j().d;
                Context a = c.j.a.d.b.e.b.a();
                if (a != null) {
                    boolean t = c.j.a.d.b.n.a.t(a);
                    for (com.ss.android.socialbase.downloader.g.c a2 : list) {
                        a(a, a2, t, i);
                    }
                    List list2 = this.a;
                    if (!(list2 == null || list2.isEmpty() || this.b != null)) {
                        this.b = new b();
                        try {
                            IntentFilter intentFilter = new IntentFilter();
                            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                            a.registerReceiver(this.b, intentFilter);
                        } catch (Throwable th) {
                            th.printStackTrace();
                            this.b = null;
                        }
                    }
                }
            }
        }
    }

    /* compiled from: DefaultAlertDialogBuilder */
    public class b extends c.j.a.d.a.h.c {
        public Builder a;

        /* compiled from: DefaultAlertDialogBuilder */
        public static class a implements e {
            public AlertDialog a;

            public a(Builder builder) {
                if (builder != null) {
                    this.a = builder.show();
                }
            }

            public void a() {
                AlertDialog alertDialog = this.a;
                if (alertDialog != null) {
                    alertDialog.show();
                }
            }

            public boolean b() {
                AlertDialog alertDialog = this.a;
                return alertDialog != null ? alertDialog.isShowing() : false;
            }
        }

        public b(Context context) {
            this.a = new Builder(context);
        }

        public f a(int i) {
            Builder builder = this.a;
            if (builder != null) {
                builder.setTitle(i);
            }
            return this;
        }

        public f b(int i, OnClickListener onClickListener) {
            Builder builder = this.a;
            if (builder != null) {
                builder.setNegativeButton(i, onClickListener);
            }
            return this;
        }

        public f c(int i, OnClickListener onClickListener) {
            Builder builder = this.a;
            if (builder != null) {
                builder.setPositiveButton(i, onClickListener);
            }
            return this;
        }

        public f a(String str) {
            Builder builder = this.a;
            if (builder != null) {
                builder.setMessage(str);
            }
            return this;
        }

        public f a(OnCancelListener onCancelListener) {
            Builder builder = this.a;
            if (builder != null) {
                builder.setOnCancelListener(onCancelListener);
            }
            return this;
        }

        public e a() {
            return new a(this.a);
        }
    }

    public static i j() {
        if (k == null) {
            synchronized (i.class) {
                if (k == null) {
                    k = new i();
                }
            }
        }
        return k;
    }

    /* JADX WARNING: Removed duplicated region for block: B:92:0x01c1 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x01c0 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:95:0x01cc A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x016d A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:86:0x016c A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x012e A:{Catch:{ all -> 0x0143 }} */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x0128 A:{Catch:{ all -> 0x0143 }} */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0147 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:86:0x016c A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x016d A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:56:0x00e2 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x0128 A:{Catch:{ all -> 0x0143 }} */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x012e A:{Catch:{ all -> 0x0143 }} */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0147 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x016d A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:86:0x016c A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:45:0x00c0 */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0147 A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:86:0x016c A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x016d A:{Catch:{ all -> 0x001f, all -> 0x0264 }} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:73:0x0143 */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Can't wrap try/catch for region: R(23:39|(2:41|(2:43|44))|45|46|(1:53)(1:52)|54|(2:56|(1:58)(15:59|61|(1:65)|66|67|68|(1:70)(1:71)|72|73|74|(2:76|(1:78)(9:79|(2:84|(1:86)(7:87|89|(1:91)(1:92)|(1:95)|94|96|97))|88|89|(0)(0)|(0)|94|96|97))|80|82|84|(0)(0)))|60|61|63|65|66|67|68|(0)(0)|72|73|74|(0)|80|82|84|(0)(0)) */
    public int a(c.j.a.d.a.l r24) {
        /*
        r23 = this;
        r1 = r23;
        r2 = r24;
        r0 = r2.a;
        r3 = 0;
        if (r0 != 0) goto L_0x000a;
    L_0x0009:
        return r3;
    L_0x000a:
        r5 = 1;
        r0 = r2.g;	 Catch:{ all -> 0x0264 }
        r6 = r1.e(r0);	 Catch:{ all -> 0x0264 }
        r7 = r2.b;	 Catch:{ all -> 0x0264 }
        r0 = android.text.TextUtils.isEmpty(r7);	 Catch:{ all -> 0x0264 }
        if (r0 == 0) goto L_0x001a;
    L_0x0019:
        return r3;
    L_0x001a:
        r0 = r1.b(r2, r7);	 Catch:{ all -> 0x001f }
        goto L_0x0038;
    L_0x001f:
        r0 = move-exception;
        r8 = r0;
        r0 = j;	 Catch:{ all -> 0x0264 }
        r9 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0264 }
        r9.<init>();	 Catch:{ all -> 0x0264 }
        r10 = "redirectSavePathIfEmpty: throwable = ";
        r9.append(r10);	 Catch:{ all -> 0x0264 }
        r9.append(r8);	 Catch:{ all -> 0x0264 }
        r8 = r9.toString();	 Catch:{ all -> 0x0264 }
        android.util.Log.w(r0, r8);	 Catch:{ all -> 0x0264 }
        r0 = 4;
    L_0x0038:
        if (r0 != 0) goto L_0x003c;
    L_0x003a:
        r8 = 1;
        goto L_0x003d;
    L_0x003c:
        r8 = 0;
    L_0x003d:
        r9 = r2.e;	 Catch:{ all -> 0x0264 }
        r10 = r2.d;	 Catch:{ all -> 0x0264 }
        r11 = android.text.TextUtils.isEmpty(r9);	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x004d;
    L_0x0047:
        r9 = r2.m;	 Catch:{ all -> 0x0264 }
        r9 = c.j.a.d.a.h.g(r7, r10, r9, r8);	 Catch:{ all -> 0x0264 }
    L_0x004d:
        r11 = r9.length();	 Catch:{ all -> 0x0264 }
        r12 = 255; // 0xff float:3.57E-43 double:1.26E-321;
        if (r11 <= r12) goto L_0x005e;
    L_0x0055:
        r11 = r9.length();	 Catch:{ all -> 0x0264 }
        r11 = r11 - r12;
        r9 = r9.substring(r11);	 Catch:{ all -> 0x0264 }
    L_0x005e:
        r11 = android.text.TextUtils.isEmpty(r10);	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x0065;
    L_0x0064:
        r10 = r9;
    L_0x0065:
        r11 = r2.m;	 Catch:{ all -> 0x0264 }
        r12 = ".apk";
        r12 = r9.endsWith(r12);	 Catch:{ all -> 0x0264 }
        if (r12 == 0) goto L_0x0079;
    L_0x006f:
        r12 = r2.m;	 Catch:{ all -> 0x0264 }
        r12 = c.j.a.d.a.h.p(r12);	 Catch:{ all -> 0x0264 }
        if (r12 != 0) goto L_0x0079;
    L_0x0077:
        r11 = "application/vnd.android.package-archive";
    L_0x0079:
        r15 = r11;
        r11 = r2.f;	 Catch:{ all -> 0x0264 }
        r12 = android.text.TextUtils.isEmpty(r11);	 Catch:{ all -> 0x0264 }
        if (r12 == 0) goto L_0x0086;
    L_0x0082:
        r11 = c.j.a.d.a.h.l();	 Catch:{ all -> 0x0264 }
    L_0x0086:
        r14 = r11;
        r11 = android.text.TextUtils.isEmpty(r14);	 Catch:{ all -> 0x0264 }
        if (r11 != 0) goto L_0x0262;
    L_0x008d:
        r11 = android.text.TextUtils.isEmpty(r9);	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x0095;
    L_0x0093:
        goto L_0x0262;
    L_0x0095:
        r13 = c.j.a.d.b.e.b.c(r7, r14);	 Catch:{ all -> 0x0264 }
        r11 = r2.L;	 Catch:{ all -> 0x0264 }
        r11 = c.j.a.d.b.l.a.f(r11);	 Catch:{ all -> 0x0264 }
        r12 = "resume_task_override_settings";
        r11 = r11.k(r12, r3);	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x00c0;
    L_0x00a7:
        r11 = c.j.a.d.b.e.b.a();	 Catch:{ all -> 0x0264 }
        r11 = c.j.a.d.b.e.i.a(r11);	 Catch:{ all -> 0x0264 }
        r11 = r11.k(r13);	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x00c0;
    L_0x00b5:
        r12 = new org.json.JSONObject;	 Catch:{ all -> 0x00c0 }
        r11 = r11.g();	 Catch:{ all -> 0x00c0 }
        r12.<init>(r11);	 Catch:{ all -> 0x00c0 }
        r2.L = r12;	 Catch:{ all -> 0x00c0 }
    L_0x00c0:
        r11 = r2.L;	 Catch:{ all -> 0x0264 }
        c.j.a.d.b.l.a.i(r13, r11);	 Catch:{ all -> 0x0264 }
        r11 = r2.v;	 Catch:{ all -> 0x0264 }
        if (r11 != 0) goto L_0x00dd;
    L_0x00c9:
        r12 = c.j.a.d.b.n.a.R(r14, r9);	 Catch:{ all -> 0x0264 }
        if (r12 == 0) goto L_0x00dd;
    L_0x00cf:
        r12 = r2.a;	 Catch:{ all -> 0x0264 }
        r12 = c.j.a.d.b.e.i.a(r12);	 Catch:{ all -> 0x0264 }
        r12 = r12.k(r13);	 Catch:{ all -> 0x0264 }
        if (r12 != 0) goto L_0x00dd;
    L_0x00db:
        r12 = 1;
        goto L_0x00de;
    L_0x00dd:
        r12 = r11;
    L_0x00de:
        r11 = r2.h;	 Catch:{ all -> 0x0264 }
        if (r11 != 0) goto L_0x00f1;
    L_0x00e2:
        r11 = r2.i;	 Catch:{ all -> 0x0264 }
        if (r11 == 0) goto L_0x00e7;
    L_0x00e6:
        goto L_0x00f1;
    L_0x00e7:
        r19 = r12;
        r20 = r13;
        r21 = r14;
        r22 = r15;
        r4 = 0;
        goto L_0x0111;
    L_0x00f1:
        r18 = new c.j.a.d.a.j.b;	 Catch:{ all -> 0x0264 }
        r11 = r2.a;	 Catch:{ all -> 0x0264 }
        r4 = r2.l;	 Catch:{ all -> 0x0264 }
        r16 = r11;
        r11 = r18;
        r19 = r12;
        r12 = r16;
        r20 = r13;
        r21 = r14;
        r14 = r10;
        r22 = r15;
        r15 = r21;
        r16 = r9;
        r17 = r4;
        r11.m8476init(r12, r13, r14, r15, r16, r17);	 Catch:{ all -> 0x0264 }
        r4 = r18;
    L_0x0111:
        r11 = new c.j.a.d.a.i$a;	 Catch:{ all -> 0x0264 }
        r11.m6386init();	 Catch:{ all -> 0x0264 }
        r12 = c.j.a.d.b.e.b.h;	 Catch:{ all -> 0x0264 }
        if (r12 == 0) goto L_0x0120;
    L_0x011a:
        r13 = r2.N;	 Catch:{ all -> 0x0264 }
        if (r13 != 0) goto L_0x0120;
    L_0x011e:
        r2.N = r12;	 Catch:{ all -> 0x0264 }
    L_0x0120:
        r12 = r2.l;	 Catch:{ all -> 0x0264 }
        r13 = android.text.TextUtils.isEmpty(r12);	 Catch:{ all -> 0x0143 }
        if (r13 != 0) goto L_0x012e;
    L_0x0128:
        r13 = new org.json.JSONObject;	 Catch:{ all -> 0x0143 }
        r13.<init>(r12);	 Catch:{ all -> 0x0143 }
        goto L_0x0133;
    L_0x012e:
        r13 = new org.json.JSONObject;	 Catch:{ all -> 0x0143 }
        r13.<init>();	 Catch:{ all -> 0x0143 }
    L_0x0133:
        r14 = "auto_install_with_notification";
        r13.put(r14, r5);	 Catch:{ all -> 0x0143 }
        r14 = "auto_install_without_notification";
        r15 = r2.i;	 Catch:{ all -> 0x0143 }
        r13.put(r14, r15);	 Catch:{ all -> 0x0143 }
        r12 = r13.toString();	 Catch:{ all -> 0x0143 }
    L_0x0143:
        r13 = r2.h;	 Catch:{ all -> 0x0264 }
        if (r13 != 0) goto L_0x014e;
    L_0x0147:
        r13 = r2.i;	 Catch:{ all -> 0x0264 }
        if (r13 == 0) goto L_0x014c;
    L_0x014b:
        goto L_0x014e;
    L_0x014c:
        r13 = 0;
        goto L_0x014f;
    L_0x014e:
        r13 = 1;
    L_0x014f:
        if (r13 == 0) goto L_0x017e;
    L_0x0151:
        r14 = c.j.a.d.b.l.a.d(r20);	 Catch:{ all -> 0x0264 }
        r15 = "enable_notification_ui";
        r14 = r14.b(r15, r3);	 Catch:{ all -> 0x0264 }
        if (r14 != r5) goto L_0x017e;
    L_0x015d:
        r14 = c.j.a.d.a.j.d.a();	 Catch:{ all -> 0x0264 }
        r15 = r2.M;	 Catch:{ all -> 0x0264 }
        java.util.Objects.requireNonNull(r14);	 Catch:{ all -> 0x0264 }
        r16 = android.text.TextUtils.isEmpty(r15);	 Catch:{ all -> 0x0264 }
        if (r16 == 0) goto L_0x016d;
    L_0x016c:
        goto L_0x017e;
    L_0x016d:
        r5 = c.j.a.d.b.e.b.r();	 Catch:{ all -> 0x0264 }
        r3 = new c.j.a.d.a.j.c;	 Catch:{ all -> 0x0264 }
        r18 = r0;
        r0 = r20;
        r3.m2340init(r14, r15, r0);	 Catch:{ all -> 0x0264 }
        r5.submit(r3);	 Catch:{ all -> 0x0264 }
        goto L_0x0182;
    L_0x017e:
        r18 = r0;
        r0 = r20;
    L_0x0182:
        r3 = r2.a;	 Catch:{ all -> 0x0264 }
        c.j.a.d.b.e.i.a(r3);	 Catch:{ all -> 0x0264 }
        r3 = new c.j.a.d.b.h.c;	 Catch:{ all -> 0x0264 }
        r3.m2415init();	 Catch:{ all -> 0x0264 }
        r5 = r3.m;	 Catch:{ all -> 0x0264 }
        r5.c = r7;	 Catch:{ all -> 0x0264 }
        r7 = r2.c;	 Catch:{ all -> 0x0264 }
        r5.m = r7;	 Catch:{ all -> 0x0264 }
        r5.a = r9;	 Catch:{ all -> 0x0264 }
        r5.b = r10;	 Catch:{ all -> 0x0264 }
        r7 = r21;
        r5.d = r7;	 Catch:{ all -> 0x0264 }
        r7 = r2.j;	 Catch:{ all -> 0x0264 }
        r5.e = r7;	 Catch:{ all -> 0x0264 }
        r5.g = r6;	 Catch:{ all -> 0x0264 }
        r3.k = r11;	 Catch:{ all -> 0x0264 }
        r6 = r2.w;	 Catch:{ all -> 0x0264 }
        r5.h = r6;	 Catch:{ all -> 0x0264 }
        r6 = r2.x;	 Catch:{ all -> 0x0264 }
        r5.i = r6;	 Catch:{ all -> 0x0264 }
        r5.n = r13;	 Catch:{ all -> 0x0264 }
        r5.f = r12;	 Catch:{ all -> 0x0264 }
        r11 = r22;
        r5.o = r11;	 Catch:{ all -> 0x0264 }
        r6 = r2.F;	 Catch:{ all -> 0x0264 }
        r5.l = r6;	 Catch:{ all -> 0x0264 }
        r6 = r2.G;	 Catch:{ all -> 0x0264 }
        r5.k = r6;	 Catch:{ all -> 0x0264 }
        r5 = r2.k;	 Catch:{ all -> 0x0264 }
        if (r5 != 0) goto L_0x01c1;
    L_0x01c0:
        goto L_0x01c8;
    L_0x01c1:
        r6 = r5.hashCode();	 Catch:{ all -> 0x0264 }
        r3.b(r6, r5);	 Catch:{ all -> 0x0264 }
    L_0x01c8:
        if (r4 != 0) goto L_0x01cc;
    L_0x01ca:
        r4 = 0;
        goto L_0x01d4;
    L_0x01cc:
        r5 = r4.hashCode();	 Catch:{ all -> 0x0264 }
        r3.j(r5, r4);	 Catch:{ all -> 0x0264 }
        goto L_0x01ca;
    L_0x01d4:
        r3.i = r4;	 Catch:{ all -> 0x0264 }
        r4 = r3.m;	 Catch:{ all -> 0x0264 }
        r5 = r19;
        r4.j = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.q;	 Catch:{ all -> 0x0264 }
        r4.q = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.r;	 Catch:{ all -> 0x0264 }
        r4.r = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.p;	 Catch:{ all -> 0x0264 }
        r3.c = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.o;	 Catch:{ all -> 0x0264 }
        r3.b = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.n;	 Catch:{ all -> 0x0264 }
        r4.p = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.s;	 Catch:{ all -> 0x0264 }
        r4.u = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.t;	 Catch:{ all -> 0x0264 }
        r4.v = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.u;	 Catch:{ all -> 0x0264 }
        r4.w = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.y;	 Catch:{ all -> 0x0264 }
        r4.x = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.z;	 Catch:{ all -> 0x0264 }
        r4.y = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.A;	 Catch:{ all -> 0x0264 }
        r4.s = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.B;	 Catch:{ all -> 0x0264 }
        r4.z = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.C;	 Catch:{ all -> 0x0264 }
        r4.t = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.D;	 Catch:{ all -> 0x0264 }
        r4.A = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.E;	 Catch:{ all -> 0x0264 }
        r4.B = r5;	 Catch:{ all -> 0x0264 }
        r5 = 0;
        r3.l = r5;	 Catch:{ all -> 0x0264 }
        r3.p = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.H;	 Catch:{ all -> 0x0264 }
        r4.C = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.I;	 Catch:{ all -> 0x0264 }
        r3.s = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.J;	 Catch:{ all -> 0x0264 }
        r3.o = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.K;	 Catch:{ all -> 0x0264 }
        r4.D = r5;	 Catch:{ all -> 0x0264 }
        r5 = 0;
        r3.q = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.L;	 Catch:{ all -> 0x0264 }
        r4.G = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.M;	 Catch:{ all -> 0x0264 }
        r4.E = r5;	 Catch:{ all -> 0x0264 }
        r5 = r2.N;	 Catch:{ all -> 0x0264 }
        r3.t = r5;	 Catch:{ all -> 0x0264 }
        r2 = r2.O;	 Catch:{ all -> 0x0264 }
        r4.H = r2;	 Catch:{ all -> 0x0264 }
        r4 = 0;
        r2 = r3.m;	 Catch:{ all -> 0x0264 }
        r2.F = r4;	 Catch:{ all -> 0x0264 }
        r2 = j;	 Catch:{ all -> 0x0264 }
        r4 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0264 }
        r4.<init>();	 Catch:{ all -> 0x0264 }
        r5 = "notification permission need not request, start download :";
        r4.append(r5);	 Catch:{ all -> 0x0264 }
        r4.append(r10);	 Catch:{ all -> 0x0264 }
        r4 = r4.toString();	 Catch:{ all -> 0x0264 }
        c.j.a.d.b.g.a.d(r2, r4);	 Catch:{ all -> 0x0264 }
        r2 = r18;
        r1.g(r3, r2, r8);	 Catch:{ all -> 0x0264 }
        return r0;
    L_0x0262:
        r2 = 0;
        return r2;
    L_0x0264:
        r0 = move-exception;
        r2 = new com.ss.android.socialbase.downloader.e.a;
        r3 = 1003; // 0x3eb float:1.406E-42 double:4.955E-321;
        r4 = "addDownloadTask";
        r4 = c.j.a.d.b.n.a.B(r0, r4);
        r2.m4677init(r3, r4);
        r3 = 0;
        r4 = 0;
        c.j.a.c.y.a.i.n(r3, r3, r2, r4);
        r2 = j;
        r3 = 1;
        r3 = new java.lang.Object[r3];
        r3[r4] = r0;
        r0 = "add download task error:%s";
        r0 = java.lang.String.format(r0, r3);
        c.j.a.d.b.g.a.g(r2, r0);
        return r4;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.i.a(c.j.a.d.a.l):int");
    }

    public final int b(l lVar, String str) {
        c.j.a.d.b.l.a f = c.j.a.d.b.l.a.f(lVar.L);
        String str2 = "anti_hijack_dir";
        JSONObject l = f.l(str2);
        int i = -1;
        if (l != null) {
            String str3 = "dir_name";
            if (!TextUtils.isEmpty(l.optString(str3))) {
                String optString;
                String str4 = lVar.d;
                CharSequence charSequence = lVar.e;
                if (TextUtils.isEmpty(charSequence)) {
                    charSequence = h.g(str, str4, lVar.m, true);
                }
                if (charSequence.length() > ISdkLite.REGION_UNSET) {
                    charSequence = charSequence.substring(charSequence.length() - ISdkLite.REGION_UNSET);
                }
                if (TextUtils.isEmpty(str4)) {
                    str4 = charSequence;
                }
                String str5 = lVar.f;
                if (TextUtils.isEmpty(str5)) {
                    str5 = h.l();
                }
                StringBuilder g = c.b.a.a.a.g(str5);
                g.append(File.separator);
                JSONObject l2 = f.l(str2);
                int i2 = 0;
                if (l2 != null) {
                    optString = l2.optString(str3);
                    if (!TextUtils.isEmpty(optString) && optString.startsWith("/")) {
                        optString = optString.substring(1);
                    }
                    if (!TextUtils.isEmpty(optString)) {
                        if (optString.contains("%s")) {
                            try {
                                str4 = String.format(optString, new Object[]{str4});
                            } catch (Throwable unused) {
                            }
                        } else {
                            str4 = c.b.a.a.a.D(optString, str4);
                        }
                        optString = str4;
                        if (optString.length() > ISdkLite.REGION_UNSET) {
                            optString = optString.substring(optString.length() - ISdkLite.REGION_UNSET);
                        }
                    }
                } else {
                    optString = "";
                }
                g.append(optString);
                str4 = g.toString();
                com.ss.android.socialbase.downloader.g.c c = c(lVar.a, str);
                if (c == null || !c.X()) {
                    if (c == null) {
                        str5 = lVar.m;
                        optString = "application/vnd.android.package-archive";
                        if (!(TextUtils.isEmpty(charSequence) || !charSequence.endsWith(".apk") || h.p(str5))) {
                            str5 = optString;
                        }
                        if (optString.equalsIgnoreCase(str5)) {
                            c.j.a.d.a.g.c cVar = g.a;
                            JSONObject l3 = f.l(str2);
                            if ((l3 != null ? TextUtils.isEmpty(l3.optString(str3)) ^ 1 : 0) == 0) {
                                i2 = 5;
                            } else if (c.j.a.d.b.l.a.f.k("get_download_info_by_list", false)) {
                                JSONArray m = f.m("anti_plans");
                                if (m != null) {
                                    int length = m.length();
                                    for (int i3 = 0; i3 < length; i3++) {
                                        JSONObject optJSONObject = m.optJSONObject(i3);
                                        if (optJSONObject != null && g.k(optJSONObject) && g.n(optJSONObject)) {
                                            String optString2 = optJSONObject.optString("type");
                                            if ("jump_file_manager".equals(optString2) || "jump_file_manager_custom".equals(optString2)) {
                                                i = g.o(optJSONObject).b;
                                                if (i == 0) {
                                                    break;
                                                }
                                            } else if ("custom_save_path".equalsIgnoreCase(optString2)) {
                                                i = g.p(optJSONObject).b;
                                                if (i == 0) {
                                                    break;
                                                }
                                            } else {
                                                continue;
                                            }
                                        }
                                    }
                                }
                                i2 = i;
                            } else {
                                i2 = 4;
                            }
                            if (i2 == 0) {
                                lVar.f = str4;
                            }
                        }
                    }
                    i2 = c != null ? 8 : 9;
                } else {
                    lVar.f = c.e;
                    try {
                        lVar.L = new JSONObject(c.g());
                    } catch (Throwable unused2) {
                    }
                }
                return i2;
            }
        }
        return -1;
    }

    public com.ss.android.socialbase.downloader.g.c c(Context context, String str) {
        if (!(TextUtils.isEmpty(str) || context == null)) {
            try {
                com.ss.android.socialbase.downloader.g.c d = d(context, str, i());
                if (d == null) {
                    d = d(context, str, context.getFilesDir());
                }
                if (d == null) {
                    d = d(context, str, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
                }
                if (d == null) {
                    d = d(context, str, context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS));
                }
                boolean k = c.j.a.d.b.l.a.f.k("get_download_info_by_list", false);
                if (d == null && k) {
                    d = h(context, str);
                }
                return d;
            } catch (Throwable th) {
                c.j.a.d.b.g.a.d(j, String.format("getAppDownloadInfo error:%s", new Object[]{th.getMessage()}));
            }
        }
        return null;
    }

    public final com.ss.android.socialbase.downloader.g.c d(Context context, String str, File file) {
        return (TextUtils.isEmpty(str) || file == null) ? null : c.j.a.d.b.e.i.a(context).b(str, file.getAbsolutePath());
    }

    public final List<com.ss.android.socialbase.downloader.g.e> e(List<com.ss.android.socialbase.downloader.g.e> list) {
        ArrayList arrayList = new ArrayList();
        String str = "User-Agent";
        Object obj = null;
        if (list != null && list.size() > 0) {
            for (com.ss.android.socialbase.downloader.g.e eVar : list) {
                if (!(eVar == null || TextUtils.isEmpty(eVar.a) || TextUtils.isEmpty(eVar.b))) {
                    if (eVar.a.equals(str)) {
                        obj = 1;
                    }
                    arrayList.add(new com.ss.android.socialbase.downloader.g.e(eVar.a, eVar.b));
                }
            }
        }
        if (obj == null) {
            arrayList.add(new com.ss.android.socialbase.downloader.g.e(str, g.f.a));
        }
        return arrayList;
    }

    public void f(Context context, int i, int i2) {
        switch (i2) {
            case BaseCode.NO_SOLUTION /*-4*/:
            case -1:
                c.j.a.d.b.e.i.a(context).j(i);
                return;
            case -3:
                h.c(context, i, true);
                return;
            case -2:
                c.j.a.d.b.e.i.a(context).i(i);
                return;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 7:
            case 8:
                try {
                    c.j.a.d.b.e.i.a(context).c(i);
                    return;
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
            default:
                return;
        }
    }

    public final void g(c.j.a.d.b.h.c cVar, int i, boolean z) {
        if (cVar != null) {
            com.ss.android.socialbase.downloader.g.c g;
            com.ss.android.socialbase.downloader.g.c a = cVar.m.a();
            cVar.a = a;
            if (a.u0 > 0) {
                cVar.c = new c.j.a.d.b.h.b(cVar);
            }
            c.j.a.d.b.e.d b = c.j.a.d.b.e.d.b();
            Objects.requireNonNull(b);
            p pVar = null;
            com.ss.android.socialbase.downloader.g.c cVar2 = cVar.a;
            int i2 = 0;
            if (cVar2 != null) {
                boolean z2 = cVar2.K;
                boolean z3 = true;
                if (c.j.a.d.b.n.a.M() || !c.j.a.d.b.n.a.r()) {
                    z2 = true;
                }
                boolean a2 = b.a(cVar2.g0());
                if (a2 < false && a2 != z2) {
                    List h;
                    if (a2) {
                        try {
                            if (c.j.a.d.b.n.a.r()) {
                                q.a(true).a(cVar2.g0());
                                g = q.a(true).g(cVar2.g0());
                                if (g != null) {
                                    q.a(false).b(g);
                                }
                                if (g.R > 1) {
                                    h = q.a(true).h(cVar2.g0());
                                    if (h != null) {
                                        q.a(false).i(cVar2.g0(), c.j.a.d.b.n.a.i(h));
                                    }
                                }
                            }
                        } catch (Throwable unused) {
                        }
                    } else if (c.j.a.d.b.n.a.r()) {
                        q.a(false).a(cVar2.g0());
                        h = q.a(false).h(cVar2.g0());
                        if (h != null) {
                            q.a(true).i(cVar2.g0(), c.j.a.d.b.n.a.i(h));
                        }
                    } else {
                        cVar.r = true;
                        q.a(true).a(1, cVar2.g0());
                    }
                }
                b.d(cVar2.g0(), z2);
                if (!z2) {
                    z3 = false;
                }
                pVar = q.a(z3);
            }
            if (pVar == null) {
                c.j.a.d.b.d.q qVar = cVar.l;
                com.ss.android.socialbase.downloader.g.c cVar3 = cVar.a;
                com.ss.android.socialbase.downloader.e.a aVar = new com.ss.android.socialbase.downloader.e.a(1003, "tryDownload but getDownloadHandler failed");
                g = cVar.a;
                if (g != null) {
                    i2 = g.o0();
                }
                c.j.a.c.y.a.i.n(qVar, cVar3, aVar, i2);
            } else if (cVar.r) {
                b.b.postDelayed(new c.j.a.d.b.e.c(b, pVar, cVar), 500);
            } else {
                pVar.x(cVar);
            }
            a = cVar.a;
            if (a != null) {
                a.g0();
            }
            com.ss.android.socialbase.downloader.g.c cVar4 = cVar.a;
            if (cVar4 != null) {
                cVar4.t("anti_hijack_error_code", Integer.valueOf(i));
            }
            if (cVar4 != null && z) {
                cVar4.t("is_save_path_redirected", Boolean.valueOf(z));
            }
        }
    }

    public final com.ss.android.socialbase.downloader.g.c h(Context context, String str) {
        Objects.requireNonNull(c.j.a.d.b.e.i.a(context));
        Objects.requireNonNull(c.j.a.d.b.e.d.b());
        List a = q.a(false).a(str);
        List a2 = q.a(true).a(str);
        List list;
        if (a == null && a2 == null) {
            list = null;
        } else if (a == null || a2 == null) {
            if (a == null) {
                a = a2;
            }
            list = a;
        } else {
            list = new ArrayList(a);
            list.addAll(a2);
        }
        if (list != null) {
            for (com.ss.android.socialbase.downloader.g.c cVar : list) {
                if (cVar != null && cVar.X()) {
                    return cVar;
                }
            }
        }
        return null;
    }

    public File i() {
        File file = null;
        if (TextUtils.isEmpty(this.g)) {
            return null;
        }
        File file2;
        try {
            file2 = new File(this.g);
            try {
                if (!file2.exists()) {
                    file2.mkdirs();
                } else if (!file2.isDirectory()) {
                    file2.delete();
                    file2.mkdirs();
                }
            } catch (Exception unused) {
                file = file2;
                file2 = file;
                return file2;
            }
        } catch (Exception unused2) {
            file2 = file;
            return file2;
        }
        return file2;
    }
}
